package com.tony.pmp.server.shiro;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Component;

/**
 * Created with IntelliJ IDEA.
 *
 * @Title: ShiroVariable
 * @Auther: 皮蛋布丁
 * @Date: 2021/07/29/10:25
 * @Description: 推送给前端使用的shiro对象变量
 */
@Component
public class ShiroVariable {

    /**
    * @Description: hasPermission 判断当前登录用户(主体)是否有 指定的权限
    * @Param: [permission]
    * @return: java.lang.Boolean
    * @Author: 皮蛋布丁
    * @Date: 2021/7/29 10:29
    */
    public Boolean hasPermission(String permission) {
        Subject subject = SecurityUtils.getSubject();

        /*if (subject != null && subject.isPermitted(permission)) {
            return true;
        }
        return false;*/

        //三元运算
        return (subject != null && subject.isPermitted(permission))? true : false;
    }

}
